import Router from 'vue-router'
import Vue from 'vue'
import VideoPlay from "../views/videoPlay/index.vue";
import WebSocketCom from "@/views/webSocketCom.vue";
import sendAudio from "@/views/sendAudio.vue";
import audioToPCM from "@/views/audioToPCM.vue";
import VideoPlayBack from "@/views/videoPlay/videoPlayBack.vue";

export const constantRoutes = [
    {
        path: '/',
        name: 'sendAudio',
        meta: { title: '登录页' }
    },
    {
        path:'/videoPlay',
        name: 'videoPlay',
        component: VideoPlay
    },
    {
        path:'/VideoPlayBack',
        name: 'VideoPlayBack',
        component: VideoPlayBack
    },
    {
        path:'/webSocketCom',
        name: 'webSocketCom',
        component: WebSocketCom
    },
    {
        path:'/sendAudio',
        name: 'sendAudio',
        component: sendAudio
    },
    {
        path:'/audioToPCM',
        name: 'audioToPCM',
        component: audioToPCM
    },
]

Vue.use(Router)

// 防止连续点击多次路由报错
let routerPush = Router.prototype.push;
let routerReplace = Router.prototype.replace;
// push
Router.prototype.push = function push(location) {
    return routerPush.call(this, location).catch(err => err)
}
// replace
Router.prototype.replace = function push(location) {
    return routerReplace.call(this, location).catch(err => err)
}

export default new Router({
    mode: 'hash',
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes
})
